package com.huawei.java.pojo;

/**
 * 增加请求
 * @author 金昊霖
 */
public final class AddRequest implements Comparable<AddRequest>{
    /**
     * 请求在该天的序号
     */
    private final int number;
    /**
     * 虚拟机编号
     */
    private final int virtualMachineId;
    /**
     * 要部署的虚拟机类型
     */
    private final VirtualMachineType virtualMachineType;
    /**
     * 部署的服务器id(如果没有部署则为null)
     */
    private Integer serverId;
    /**
     * 部署的节点，0表示双节点部署，1表示布置在A节点，2表示布置在B节点
     */
    private int node;

    /**
     * 资源大小
     */
    private int resource;

    /**
     * 这里只进行一比一比大小，加因子可能会有优化
     */
    @Override
    public int compareTo(AddRequest r) {
        int source1=getResource();
        int source2=r.getResource();
        if(virtualMachineType.getType()==1&&r.getVirtualMachineType().getType()==1){
            return Integer.compare(source2, source1);
        }else if (virtualMachineType.getType()==1){
            return -1;
        }else if (r.getVirtualMachineType().getType()==1){
            return 1;
        }
        return Integer.compare(source2, source1);
    }


    public AddRequest(int number, Integer virtualMachineId, VirtualMachineType virtualMachineType) {
        this.number = number;
        this.virtualMachineId = virtualMachineId;
        this.virtualMachineType = virtualMachineType;
    }

    public int getResource() {
        if (resource==0){
            resource=virtualMachineType.getCores()+virtualMachineType.getMemory();
        }
        return resource;
    }

    public int getNumber() {
        return number;
    }


    public int getVirtualMachineId() {
        return virtualMachineId;
    }

    public VirtualMachineType getVirtualMachineType() {
        return virtualMachineType;
    }

    public Integer getServerId() {
        return serverId;
    }

    public void setServerId(Integer serverId) {
        this.serverId = serverId;
    }

    public int getNode() {
        return node;
    }

    public void setNode(Integer node) {
        this.node = node;
    }

}
